//
//  LENowTableCell.m
//  qqqqqq
//
//  Created by iOSer on 2017/3/16.
//  Copyright © 2017年 iOSer. All rights reserved.
//

#import "LENowTableCell.h"
@interface LENowTableCell()
@property(nonatomic,strong) UILabel *nameLab;
@property(nonatomic,strong) UILabel *priceLab;
@end
@implementation LENowTableCell

+(instancetype)LENowTableCellWithTableView:(UITableView *)tableView{
    static NSString * ID = @"LENowTableCell";
    LENowTableCell* cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[LENowTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
-(void)setCommodity:(LECommodity *)commodity{
    _commodity = commodity;
    self.nameLab.text = commodity.name;
    long fromNum,toNum;
//    long toNum;
    switch (commodity.priceType) {
        case defaultPrice:
            fromNum = [commodity.defaultPrice[0] longValue];
            toNum = [commodity.defaultPrice[1] longValue];
            break;
        case lowPrice:
            fromNum = [commodity.lowPrice[0] longValue];
            toNum = [commodity.lowPrice[1] longValue];
            break;
        case HiPrice:
            fromNum = [commodity.highliPrice[0] longValue];
            toNum = [commodity.highliPrice[1] longValue];
            break;
        default:
            break;
    }
    if (_commodity.isRefresh == YES) {
        commodity.nowPrice = (long)(fromNum + (arc4random() % (toNum - fromNum + 1)));
    }
    self.priceLab.text = [NSString stringWithFormat:@"￥%ld", commodity.nowPrice];
    _commodity.isRefresh = NO;
}
-(void)setupUI{
    [self.contentView addSubview:self.nameLab];
    [self.contentView addSubview:self.priceLab];
    [_nameLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self.contentView);
        make.width.equalTo((SCREEN_WIDTH/2-40)/2);
    }];
    [_priceLab makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self.contentView);
        make.width.equalTo((SCREEN_WIDTH/2-40)/2);
    }];
}
-(UILabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] initWithTitle:@"羊屎蛋" color:HEXColor(0x000000, 1) sizeFont:GGRealValue(10)];
        _nameLab.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLab;
}

-(UILabel *)priceLab{
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] initWithTitle:@"￥20000" color:HEXColor(0x000000, 1) sizeFont:GGRealValue(10)];
        _priceLab.textAlignment = NSTextAlignmentCenter;
    }
    return _priceLab;
}
@end
